<template>
	<view class="fui-wrap">
		<fui-result v-if="err" type="fail" title="操作失败" :descr="err">
			<fui-button @click="$reLaunch('parking/menus')" width="400rpx" height="84rpx" text="返回菜单" type="success" bold :margin="['48rpx','0','24rpx']"></fui-button>
		</fui-result>
		<block v-else>
			<fui-form error-position="1" labelColor="#7a7a7a" ref="form" top="0">
				<fui-form-item label="车牌号">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="records.plate_number"></fui-input>
				</fui-form-item>
				<fui-form-item label="入场时间">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="records.entry_time_txt"></fui-input>
				</fui-form-item>
				<fui-form-item label="费用合计">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="'￥'+total_fee"></fui-input>
				</fui-form-item>
				<block v-if="coupon!='无'">
				<fui-form-item label="停车券">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="coupon"></fui-input>
				</fui-form-item>
				<fui-form-item label="免减金额">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="'￥'+activities_fee"></fui-input>
				</fui-form-item>
				</block>
				<fui-form-item label="预付金额" v-if="pay_fee>0">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="'￥'+pay_fee"></fui-input>
				</fui-form-item>
				<fui-form-item label="实际支付" v-if="need_pay_fee!=total_fee">
					<fui-input readonly :borderBottom="false" :padding="[0]" :value="'￥'+need_pay_fee"></fui-input>
				</fui-form-item>
				<fui-form-item label="支付方式">
					<fui-radio-group name="radio" v-model="pay_type">
						<view class="fui-list__item">
							<fui-label>
								<view class="fui-align__center">
									<fui-radio scaleRatio="0.8" borderRadius="6rpx" value="scanqrcode" checked></fui-radio>
									<text style="margin-left: 10rpx;" class="fui-text">扫码付款</text>
								</view>
							</fui-label>
							<fui-label :margin="['0','0','0','40rpx']">
								<view class="fui-align__center">
									<fui-radio scaleRatio="0.8" borderRadius="6rpx" value="underline"></fui-radio>
									<text style="margin-left: 10rpx;" class="fui-text">线下收款</text>
								</view>
							</fui-label>
						</view>
					</fui-radio-group>
				</fui-form-item>
				<fui-form-item v-if="pay_type=='scanqrcode'">
					<view class="qrcode">
						<image :src="qrcode" style="width: 300rpx;height: 300rpx;"></image>
					</view>
				</fui-form-item>
				<fui-form-item label="备注" prop="remark">
					<fui-input :borderBottom="false" :padding="[0]" placeholder="请输入备注" v-model="remark"></fui-input>
				</fui-form-item>
				<view class="fui-btn__box">
					<fui-button :disabled="disabledButton" text="提交" bold @click="submit"></fui-button>
				</view>
			</fui-form>
		</block>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		components:{
			
		},
		data() {
			return {
				err:'',
				records:'',
				total_fee:'',
				activities_fee:'',
				pay_fee:'',
				need_pay_fee:'',
				coupon:'',
				remark:'',
				pay_type:'scanqrcode',
				disabledButton:false,
				qrcode:''
			}
		},
		onLoad(e) {
			this.$get('parking/records/pay-info',{plate_number:e.plate_number}).then(res=>{
				this.records=res.records;
				this.total_fee=res.total_fee;
				this.activities_fee=res.activities_fee;
				this.pay_fee=res.pay_fee;
				this.need_pay_fee=res.need_pay_fee;
				this.coupon=res.coupon;
				let token=uni.getStorageSync('token');
				this.qrcode=baseUrl+'parking/records/qrcode?token='+token+'&records_id='+this.records.id
			}).catch(err=>{
				this.err=err.msg;
			});
		},
		methods: {
			...methods,
			submit:function(){
				this.disabledButton=true;
				this.$post('parking/records/pay',{
					records_id:this.records.id,
					pay_type:this.pay_type,
					remark:this.remark
				},true,true).then(res=>{
					this.$redirectTo('parking/records/list',1500);
				}).catch(err=>{
					this.disabledButton=false;
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.fui-btn__box{
	padding: 20rpx;
}
.fui-list__item{
	display: flex;
	justify-content: space-between;
	width: 80%;
}
.qrcode{
	text-align: center;
	background-color: #fff;
}
</style>